package com.xianniu.ltc.mapper;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xianniu.ltc.model.entity.TXnLeadDTO;
import com.xianniu.ltc.model.po.QueryLeadAdminPO;
import com.xianniu.ltc.model.po.QueryLeadHighSeaPO;
import com.xianniu.ltc.model.po.TransferTeamPO;
import com.xianniu.ltc.model.po.report.ReportLeadPO;
import com.xianniu.ltc.model.vo.XnLeadVO;
import com.xianniu.ltc.model.vo.report.ReportLeadInfoVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * @description 线索表
 * @author wangruijie@zencor.cn
 * @date 2021-06-09
 */
@Mapper
public interface TXnLeadMapper extends BaseMapper<TXnLeadDTO> {

    @InterceptorIgnore(tenantLine = "on")
    IPage<XnLeadVO> selectPageList(@Param("page") Page page, @Param("po") QueryLeadAdminPO po, @Param("delYn") Integer delYn, @Param("tenantCode") String tenantCode);

    @InterceptorIgnore(tenantLine = "on")
    IPage<XnLeadVO> selectFallbackPageList(@Param("page") Page page, @Param("po") QueryLeadAdminPO po, @Param("delYn") Integer delYn, @Param("tenantCode") String tenantCode);

    XnLeadVO detailPLeadForAdmin(String id);

    XnLeadVO detailCLeadForAdmin(String id);

    int updateBatchForIdList(@Param("leadId") String leadId, @Param("teamId") String teamId);

    int deleteBatchForIdList(@Param("leadId") String leadId);

    /**
     * 私海线索修改:线索组转移线索
     * @return
     */
    int transferPLeadTeamForAdmin(@Param("fromTeam") String fromTeam, @Param("toTeam") String toTeam);

    /**
     * 公海线索修改:线索组转移线索
     * @return
     */
    int transferCLeadTeamForAdmin(@Param("fromTeam") String fromTeam, @Param("toTeam") String toTeam);


    @InterceptorIgnore(tenantLine = "on")
    List<XnLeadVO> selectLeadForRecycle(@Param("po") QueryLeadHighSeaPO po, @Param("list")List<String> deptArray, @Param("delYn") Integer delYn, @Param("tenantCode") String tenantCode);

    @InterceptorIgnore(tenantLine = "on")
    List<XnLeadVO> selectHighSeaPageList(@Param("po") QueryLeadHighSeaPO po, @Param("list")List<String> deptArray, @Param("delYn") Integer delYn, @Param("tenantCode") String tenantCode);

    @InterceptorIgnore(tenantLine = "on")
    List<XnLeadVO> selectCommonHighSeaPageList(@Param("po") QueryLeadHighSeaPO po, @Param("list")List<String> deptArray, @Param("delYn") Integer delYn, @Param("tenantCode") String tenantCode);


    /**
     * 查询勾选的线索对应的负责人：判断是不是当前登录人
     */
    String selectHeadBy(String leadId);

    int receiveLead(String leadId, String receiveBy);


    /**
     * 根据当前登录人是领取人：查询私海线索
     * @param page
     * @param po
     * @param receiveBy
     * @param delYn
     * @param tenantCode
     * @return
     */
    @InterceptorIgnore(tenantLine = "on")
    IPage<XnLeadVO> selectLeadForPrivateSea(@Param("page") Page page, @Param("po") QueryLeadHighSeaPO po, @Param("receiveBy") String receiveBy, @Param("delYn") Integer delYn, @Param("tenantCode") String tenantCode);

    int putBackById(String id);


    /**
     * 线索管理：根据条件查询导出线索
     * @param page
     * @param po
     * @return
     */
    List<XnLeadVO> selectExportList(@Param("page") Page page, @Param("po") QueryLeadAdminPO po, @Param("tenantCode") String tenantCode);

    /**
     * 自定义报表数据查询-公私海线索数据
     * @param page
     * @param po
     * @return
     */
    IPage<ReportLeadInfoVO> selectReportPageList(@Param("page") Page page, @Param("po") ReportLeadPO po);

    /**
     * 自定义线索报表-通过线索对应的商机查询对应的商机的售前协同的的下一步审批人
     * @param nicheId
     * @return
     */
    List<String> selectNextApprovalUserByNicheId(String nicheId);

}

